package torres.item.interactive;

import java.util.ArrayList;
import java.util.List;

import torres.entity.Entity;
import torres.item.Item;


/**
 * @author Torres
 * Represents an item that is placed on the map and is consumed
 * only if certain conditions are met.
 */
@SuppressWarnings("serial")
public class InteractiveItem extends Item 
{
	private List<Interaction> intList;
	
	
	/**
	 * Creates a new InteractiveItem with the specified name and no Interactions.
	 * @param name The name of the Interactive item.
	 */
	public InteractiveItem(String name) {
		this.setConsumed(false);
		this.setName(name);
		this.setAsciiRep("I");
		
		//this.imageName = "sword.png";
		this.intList = new ArrayList<Interaction>();
	}
	
	/**
	 * Creates a new InteractiveItem with the specified name and list of Interactions.
	 * @param name The name of the Interactive item.
	 * @param intList The list of Interactions to be applied on use.
	 */
	public InteractiveItem(String name, List<Interaction> intList) {
		this(name);
		this.setInteractions(intList);
	}
	
	/**
	 * Creates a new InteractiveItem which is a copy of the specified InteractiveItem.
	 * @param item The InteractiveItem to be copied.
	 */
	public InteractiveItem(InteractiveItem item) {
		this(item.getName(), item.getInteractions());
	}
	
	/**
	 * Triggers the effect of an Entity walking on this item.
	 * @param e The Entity that is walking on this item
	 */
	public void onTouch(Entity e) {
		if(this.getInteractions() != null)
			for(Interaction i : this.getInteractions()) 
				i.use(e);
	}
	
	
	/**
	 * Returns the list of Interactions that this item performs on touch.
	 * @return The list of Interactions that this item performs on touch.
	 */
	protected List<Interaction> getInteractions() {
		return this.intList;
	}
	
	/**
	 * Sets the list of Interactions that this item performs on touch.
	 * @param ints The list of Interactions that this item performs on touch.
	 */
	private void setInteractions(List<Interaction> ints) {
		this.intList = ints;
	}
	
	/**
	 * Adds the specified Interaction to this InteractiveItem.
	 * @param interaction The Interaction to be added to this InteractiveItem.
	 */
	public void addInteraction(Interaction interaction) {
		
		intList.add(interaction);
	}

	/**
	 * Adds all of the Interactions in the List to this InteractiveItem.
	 * @param intList The list of Interactions to be added to this InteractiveItem.
	 */
	public void appendInteractionList(List<Interaction> intList)
	{
		this.intList.addAll(intList);
	}
}
